package com.smyk.btchina.base

import android.os.Bundle
import android.view.View
import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding
import com.airbnb.lottie.LottieAnimationView
import com.smyk.btchina.R

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope


/**
 * @des
 * @date 2021/7/2
 * @author sam
 */
abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity(), CoroutineScope by MainScope() {

    protected val mBinding: VB by lazy { getViewBing() }
    protected lateinit var loadingView: LottieAnimationView
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.layout_base_container)
        loadingView = findViewById(R.id.anim_loading)
        findViewById<FrameLayout>(R.id.fl_container).addView(mBinding.root)
        initView()
        initClick()
        initData()
    }

    abstract fun getViewBing(): VB

    abstract fun initView()

    open fun initClick(){

    }

    open fun initData(){

    }

    fun showLoading() {
        loadingView.visibility = View.VISIBLE
        loadingView.playAnimation()
    }

    fun dismissLoading() {
        loadingView.visibility = View.GONE
        loadingView.cancelAnimation()
    }


}